Function search_outsource(ByVal nameStr As String, ByVal outsourceStr As String, Optional ByVal sign As String = "、")

Dim nameArr, outsourceArr, strDic
Dim resultStr As String
Dim count As Integer
Dim marker As String

marker = "外包"

count = 0

'创建对象集合
Set strDic = CreateObject("Scripting.Dictionary")

'去除空格
nameStr = Replace(nameStr, " ", "")
outsourceStr = Replace(outsourceStr, " ", "")

'通过分隔符创建字符串数组
nameArr = Split(nameStr, sign)
outsourceArr = Split(outsourceStr, sign)

'循环字符串数组
For Each outsource In outsourceArr
    strDic.Item(outsource) = outsource
Next

'循环对象集合
For Each strItem In nameArr
    '拼接结果集字符串
    Dim sartIndex As Integer
    Dim name As String
    
    '查找英文括号位置
    sartIndex = InStr(strItem, "(")
    '如果没有找到，则查找中文括号
    If sartIndex = 0 Then
       sartIndex = InStr(strItem, "（")
    End If
    
    If sartIndex > 0 Then
        name = Left(strItem, sartIndex - 1)
    Else
        name = strItem
    End If
    
    If strDic.Exists(name) Then
        '如果当前姓名包含括号
        If sartIndex > 0 Then
            name = Left(strItem, sartIndex) + marker + Right(strItem, Len(strItem) - sartIndex)
        Else
            name = name + "(" + marker + ")"
        End If
        
        resultStr = resultStr + name + sign
        count = count + 1
        
    Else
        resultStr = resultStr + strItem + sign
    End If
    
Next

'去除最后一位字符
resultStr = Left(resultStr, Len(resultStr) - 1)
'去重空格
resultStr = Replace(resultStr, " ", "")
'返回最终结果
search_outsource = resultStr + " count:" + str(count)

End Function
